<template>
	<view :style="themeColor">
		<view class="page">
			<view class="flex flex-direction flex-wrap align-stretch benben-position-layout flex addTask_flex_0"
				:style="{height:(88+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx', }">
				<view class='flex flex-wrap align-center justify-between addTask_fd0_0'>
					<view class='flex flex-wrap align-center addTask_fd0_0_c0' @tap.stop="handleJumpDiy"
						data-type="back" data-url="1">
						<text class='fu-iconfont2  addTask_fd0_0_c0_c0'>&#xE794;</text>
					</view>
					<view class='flex flex-wrap align-center'>
						<text class='addTask_fd0_0_c1_c0'>添加学习任务</text>
					</view>
					<view class='flex align-center justify-end addTask_fd0_0_c0'>
					</view>
				</view>

			</view>
			<view :style="{height: (88+StatusBarRpx)+'rpx'}"></view>
			<!---flex布局flex布局开始-->
			<view class="flex flex-direction flex-wrap align-stretch benben-flex-layout addTask_flex_1">
				<view class='flex flex-wrap align-center addTask_fd1_0'>
					<text class='addTask_fd1_0_c0001'>*</text>
					<text class='addTask_fd1_0_c0'>任务名称</text>
					<benben-input class='flex-sub addTask_fd1_0_c1' type="text" :placeholder="`请输入任务名称`"
						confirm-type="done" :maxlength="50"
						placeholder-style="color:rgba(191, 191, 191, 1);font-size:32rpx" v-model="studyData.task" />
				</view>
				<view class='flex flex-wrap align-center addTask_fd1_0' @tap.stop="pickerDiy1696933342022=true">
					<text class='addTask_fd1_0_c0001'>*</text>
					<text class='addTask_fd1_0_c0'>课程名称</text>
					<benben-input class='flex-sub addTask_fd1_0_c1' type="text" :placeholder="`请选择课程名称`"
						confirm-type="done" :maxlength="-1" :disabled='true'
						placeholder-style="color:rgba(191, 191, 191, 1);font-size:32rpx"
						v-model="studyData.kechengmingcheng" />
					<image class='addTask_fd1_1_c2' mode="aspectFit" :src='STATIC_URL+"2.png"'></image>
				</view>
				<view class='flex flex-wrap align-center addTask_fd1_0' @tap.stop="pickerDiy1696934227365=true">
					<text class='addTask_fd1_0_c0001'>*</text>
					<text class='addTask_fd1_0_c0'>截止时间</text>
					<benben-input class='flex-sub addTask_fd1_0_c1' type="text" :disabled='true'
						:placeholder="`请选择截止时间`" confirm-type="done" :maxlength="-1"
						placeholder-style="color:rgba(191, 191, 191, 1);font-size:32rpx" v-model="studyData.end_time" />
					<image class='addTask_fd1_1_c2' mode="aspectFit" :src='STATIC_URL+"2.png"'></image>
				</view>
			</view>

			<!---flex布局flex布局结束-->
			<view class="flex flex-wrap align-start justify-center benben-position-layout flex addTask_flex_2">
				<button class='addTask_fd2_0' @tap.stop="postLearningTasksFunc()">提交</button>

			</view>
			<view :style="{height: '120rpx'}"></view>
			<!--课程名称选择器开始 -->
			<benben-picker ref="benbenWritePickerCodepicker3" :visible.sync="pickerDiy1696933342022"
				:label.sync='studyData.kechengmingcheng' :value.sync='studyData.freexianshangkecheng_id'
				:options='courseType' mode='selector' :mask-show='true' :timeout='true' :picker-height='88'
				default-type='aid' :default-props='{"label":"kechengmingcheng","value":"aid"}'>
				<template #picker-header>
					<view class='flex flex-wrap align-center justify-between addTask_picker3_0'>
						<text class='addTask_picker3_0_c0' @tap="$refs.benbenWritePickerCodepicker3.cancel()">取消</text>
						<text class='addTask_picker3_0_c1'>请选择</text>
						<text class='addTask_picker3_0_c2'
							@tap="$refs.benbenWritePickerCodepicker3.pickerConfirm()">确认</text>
					</view>
				</template>
			</benben-picker>
			<!--课程名称选择器结束 -->
			<!--截止时间选择器开始 -->
			<benben-picker ref="benbenWritePickerCodepicker4" :visible.sync="pickerDiy1696934227365"
				:value.sync='studyData.end_time' mode='date' :picker-height='88' :current='true' :mask-show='true'
				fields='day' :timeout='true' start-year='现在' end-year='2050-12-31' from-data=''>
				<template #picker-header>
					<view class='flex flex-wrap align-center justify-between addTask_picker4_0'>
						<text class='addTask_picker4_0_c0' @tap="$refs.benbenWritePickerCodepicker4.cancel()">取消</text>
						<text class='addTask_picker4_0_c1'>请选择</text>
						<text class='addTask_picker4_0_c2'
							@tap="$refs.benbenWritePickerCodepicker4.pickerConfirm()">确认</text>
					</view>
				</template>
			</benben-picker>
			<!--截止时间选择器结束 -->


		</view>
	</view>
</template>
<script>
	import {
		validate
	} from '@/common/utils/validate.js'

	export default {
		components: {},


		data() {
			return {
				"pickerDiy1696934227365": false,
				"pickerDiy1696933342022": false,
				"courseType": [],
				"studyData": {
					"aid": "",
					"usermerchant_id": "",
					"task": "",
					"freexianshangkecheng_id": "",
					"end_time": "",
					"kechengmingcheng": ""
				},
				"shopID": "",
				"id": ""
			};
		},
		computed: {
			themeColor() {
				return this.$store.getters.themeColor
			},

		},
		watch: {},
		onLoad(options) {
			let {
				id,
				shopID
			} = options
			if (id !== undefined) this.id = id
			if (shopID !== undefined) this.shopID = shopID
			this.getStudyFunc()
		},
		onUnload() {

		},
		onReady() {

		},
		onShow() {
			this.shopID = uni.getStorageSync('shopID') || ''
			this.getCourseFunc()
		},
		onHide() {

		},
		onResize() {

		},
		onPullDownRefresh() {

		},
		onReachBottom(e) {

		},
		onPageScroll(e) {

		},
		methods: {
			//获取课程名称信息
			async getCourseFunc() {
				//请求方法
				//数据验证

				let datacourseType = await this.$api.get(global.apiUrls.post6525243bf386e, {
					shopID: this.shopID
				});

				if (datacourseType.data.code != 1) {
					this.$message.info(datacourseType.data.msg);
					return
				}
				let infocourseType = datacourseType.data;
				this.courseType = infocourseType.data

			},
			//提交学习任务
			async postLearningTasksFunc() {
				if (!validate(this.studyData.task, 'require')) {
					this.$message.info('请输入任务名称');
					return false;
				}
				if (!validate(this.studyData.freexianshangkecheng_id, 'require')) {
					this.$message.info('请选择课程名称');
					return false;
				}
				if (!validate(this.studyData.end_time, 'require')) {
					this.$message.info('请选择截止时间');
					return false;
				}
				//请求方法
				//数据验证

				let data6524e826d3e25 = await this.$api.dbPost(global.apiUrls.post6524e826d3e25, {
					aid: this.id,
					task: this.studyData.task,
					usermerchant_id: this.shopID,
					freexianshangkecheng_id: this.studyData.freexianshangkecheng_id,
					end_time: this.studyData.end_time
				});
				if (!data6524e826d3e25) return
				if (data6524e826d3e25.data.code != 1) {
					this.$message.info(data6524e826d3e25.data.msg);
					return
				}



				if (this.id == '') {
					this.$message.info('添加成功');
					setTimeout(() => {
						this.$urouter.navigateBack(1);
					}, 500)
				} else if (this.id != '') {
					this.$message.info('修改成功');
					setTimeout(() => {
						this.$urouter.navigateBack(1);
					}, 500)
				}
			},
			//获取学习任务信息
			async getStudyFunc() {
				//请求方法
				//数据验证

				let datastudyData = await this.$api.get(global.apiUrls.post652504892f479, {
					aid: this.id
				});

				if (datastudyData.data.code != 1) {
					this.$message.info(datastudyData.data.msg);
					return
				}
				let infostudyData = datastudyData.data;
				this.studyData = infostudyData.data

			}
		}
	};
</script>
<style lang="scss" scoped>
	.page {
		width: 100vw;
		overflow-x: hidden;
		min-height: calc(100vh - var(--window-bottom));
		background: var(--benbenbgColor1);
		background-size: 100% auto;
	}

	.addTask_flex_0 {
		border-bottom: 1px solid #eee;
		background: #fff;
		width: 750rpx;
		height: 88rpx;
		overflow: hidden;
		z-index: 10;
		top: 0rpx;
		background-size: 100% auto !important;
	}

	.addTask_fd0_0_c1_c0 {
		font-size: 36rpx;
		font-weight: 500;
		color: #333333;
	}

	.addTask_fd0_0_c0_c0 {
		font-size: 36rpx;
		color: #333;
		font-weight: 500;
	}

	.addTask_fd0_0_c0 {
		width: 100rpx;
		height: 88rpx;
	}

	.addTask_fd0_0 {
		padding: 0rpx 32rpx 0rpx 32rpx;
		height: 88rpx;
	}

	.addTask_flex_1 {
		margin: 0rpx 32rpx 0rpx 32rpx;
	}

	.addTask_fd1_1_c2 {
		width: 12rpx;
		height: 22rpx;
		border-radius: 0rpx 0rpx 0rpx 0rpx;
		margin: 0rpx 0rpx 6rpx 15rpx;
	}

	.addTask_fd1_0_c1 {
		font-size: 32rpx;
		font-weight: 400;
		color: #333;
		text-align: right;
		margin: 0rpx 0rpx 0rpx 24rpx;
	}

	.addTask_fd1_0_c0001 {
		font-size: 32rpx;
		font-weight: 400;
		color: rgba(227, 29, 26, 1);
		line-height: 40rpx;
		margin-right: 10rpx;
	}

	.addTask_fd1_0_c0 {
		font-size: 32rpx;
		font-weight: 400;
		color: #333;
		line-height: 40rpx;
	}

	.addTask_fd1_0 {
		border-bottom: 1px solid #eee;
		padding: 32rpx 0rpx 32rpx 0rpx;
	}

	.addTask_flex_2 {
		width: 750rpx;
		height: 120rpx;
		overflow: hidden;
		z-index: 10;
		bottom: calc(0rpx + var(--window-bottom));
	}

	.addTask_fd2_0 {
		background: #E31D1A;
		border-radius: 44rpx 44rpx 44rpx 44rpx;
		font-size: 32rpx;
		color: #fff;
		width: 686rpx;
		height: 88rpx;
		line-height: 88rpx;
	}

	.addTask_picker3_0_c2 {
		color: #4781f5;
		font-size: 32rpx;
		font-weight: 400;
		line-height: 40rpx;
	}

	.addTask_picker3_0_c1 {
		font-size: 36rpx;
		font-weight: 400;
		color: #333;
		line-height: 50rpx;
	}

	.addTask_picker3_0_c0 {
		font-size: 32rpx;
		font-weight: 400;
		color: #333;
		line-height: 40rpx;
	}

	.addTask_picker3_0 {
		border-bottom: 1px solid #eee;
		background: #fff;
		padding: 0rpx 32rpx 0rpx 32rpx;
		border-radius: 25rpx 25rpx 0rpx 0rpx;
		background-size: 100% auto !important;
		height: 110rpx;
	}

	.addTask_picker4_0_c2 {
		color: #4781f5;
		font-size: 32rpx;
		font-weight: 400;
		line-height: 40rpx;
	}

	.addTask_picker4_0_c1 {
		font-size: 36rpx;
		font-weight: 400;
		color: #333;
		line-height: 50rpx;
	}

	.addTask_picker4_0_c0 {
		font-size: 32rpx;
		font-weight: 400;
		color: #333;
		line-height: 40rpx;
	}

	.addTask_picker4_0 {
		border-bottom: 1px solid #eee;
		background: #fff;
		padding: 0rpx 32rpx 0rpx 32rpx;
		border-radius: 25rpx 25rpx 0rpx 0rpx;
		background-size: 100% auto !important;
		height: 110rpx;
	}
</style>